using System;
using Daemon.Common.Cache;
using Daemon.Data.Substructure.Framework;
namespace Daemon.Service.Contract
{
    public class OperationManager : BaseOperationManager, IDisposable
    {
        private const string OPERATION_CACHE_KEY = "DAEMON_OPERATIONS_CACHE";
        private readonly IDaemonDistributedCache _distributedCache;

        public OperationManager(IDaemonDistributedCache cache)
        {
            _distributedCache = cache;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
        }

        protected override T DataGet<T>(string id)
        {
            return _distributedCache.HashGet<T>(OPERATION_CACHE_KEY, id);
        }

        protected override void DataSet(string id, object operation, DateTime expirationHours)
        {
            _distributedCache.HashSet(OPERATION_CACHE_KEY, id, operation);
        }

        protected override void DataAdd<T>(string id, object operation, Action<T> removeCallback)
        {
            _distributedCache.HashSet(OPERATION_CACHE_KEY, id, operation);
        }

        protected override void DataRemove(string id)
        {
            _distributedCache.Remove(OPERATION_CACHE_KEY);
        }
    }
}